From: Aaron Schulz Date: Mon, 26 May 2008 22:10:08 +0000 (+0000) Subject: Fix duplicate row removal X-Git-Tag: 1.31.0-rc.0~47370 X-Git-Url: http://git.cyclocoop.org/%22.%24info%5B?a=commitdiff_plain;h=4c1d591810869fa6ef5172e73dfdb95b53cd6e12;p=lhc%2Fweb%2Fwiklou.git Fix duplicate row removal --- diff --git a/includes/SpecialWhatlinkshere.php b/includes/SpecialWhatlinkshere.php index 346a83b6e4..f871d20eb6 100644 --- a/includes/SpecialWhatlinkshere.php +++ b/includes/SpecialWhatlinkshere.php @@ -349,8 +349,10 @@ class WhatLinksHerePager extends AlphabeticPager { } /** - * Do a query with specified parameters, rather than using the object - * context + * Do a query with specified parameters + * Note: in theory this could miss results if there were + * so many rows with the same page_id that the UNION table was + * exhausted and more rows should have been scanned in it's creation. * * @param string $offset Index offset, inclusive * @param integer $limit Exact query limit @@ -388,8 +390,9 @@ class WhatLinksHerePager extends AlphabeticPager { $SQLqueries[] = '('.$this->mDb->selectSQLText( $tables, $fields, $conds, $fname, $options, $join_conds ).')'; } // Contruct the final query. UNION the mini-queries and merge the results. + $SQL = 'SELECT * FROM (' . implode(' UNION ',$SQLqueries) . ') AS result_links'; // Remove duplicates within the result set. - $SQL = implode(' UNION DISTINCT ',$SQLqueries); + $SQL .= ' GROUP BY page_id'; // Use proper order of result set $SQL .= $descending ? " ORDER BY {$this->mIndexField} DESC" : " ORDER BY {$this->mIndexField}"; // Cut off at the specified limit